package com.mlink.service.client;

import com.mlink.entity.User;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;
import java.util.Map;

/**
 * @author LSH
 * @version 1.1
 * @date 2018/10/15
 * @Description
 */
@FeignClient(name = "user-service", fallback = UserClient.UserClientFallback.class)
public interface UserClient {

    /**
     * @param phone
     * @return 返回对象
     */
    @GetMapping(value = "/getUserByPhone")
    User getUserByPhone(@RequestParam(value = "phone") String phone);

    /**
     * @param username
     * @return  返回对象集合
     */
    @GetMapping(value = "/queryAll")
    List<User> queryAll(@RequestParam(value = "username",required = false) String username);

    /**
     * @param map map形式参数
     * @return  返回对象集合
     */
    @GetMapping(value = "/queryAllForMap")
    List<User> queryAll(@RequestParam Map<Object, Object> map);

    /**
     *  无返回值
     * @param user 对象参数
     */
    @PostMapping(value = "/User/add")
    void add(@RequestBody User user);

    @Component
    class UserClientFallback implements UserClient {
        @Override
        public User getUserByPhone(String phone) {
            System.out.println("连接超时++++++");
            return new User();
        }

        @Override
        public List<User> queryAll(String phone) {
            return null;
        }

        @Override
        public List<User> queryAll(Map<Object, Object> map) {
            return null;
        }


        @Override
        public void add(User user) {
            System.out.println("连接超时++++++");
        }
    }


}
